<script>
export default {
    data(){
        return {
            data: [],
            columns7: [
                    {
                        title: '子节点名称',
                        key: 'title',
                        render: (h, params) => {
                            return h('div', [
                                h('Icon', {
                                    props: {
                                        type: 'person'
                                    }
                                }),
                                h('strong', params.row.title)
                            ]);
                        }
                    },
                    {
                        title: 'Action',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            console.log(params)
                                            this.modal2=true
                                            this.ctitle=params.row.title
                                            this.cid=params.row.id
                                            // this.ctitle=params.row.title
                                            // this.show(params.index)
                                        }
                                    }
                                }, '修改'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {

                                            console.log(params.row.id)
                                            this.$Modal.confirm({
                                                title: '确认删除数据吗?',
                                                content: '请确认是否删除该记录！',
                                                onOk: () => {
                                                    this.axios({
                                                            url: `http://localhost:3000/cate/data/${params.row.id}`,
                                                            method: 'delete'
                                                        }).then(res=>{
                                                           
                                                            this.remove(params.index)
                                                             this.getTreedata();
                                                    })
                                                }
                                            });

                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ],

        }
    },
    methods:{
          getTreedata() {
                this.axios({
                    url:`http://localhost:3000/cate/tree`,
                    method:'get'
                }).then(res=>{
                
                    var tree=res.data;
                    // console.log(tree);
                    this.data=tree;
                  
                   
                })
            },
            onSelectChange(data){
               this.tableData=[];
            this.parentId=data[0]._id
            if(data[0].children.length>0){
                    for(var i=0;i<data[0].children.length;i++){
                       this.tableData.push({
                            title:data[0].children[i].title,
                            id:data[0].children[i]._id
                        })
                    }   
                }

            },

    }
}
</script>
